package com.cc.self.ctrl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.enjoyun.bmc.common.util.AppUtil;
import com.enjoyun.bmc.common.util.WebUtil;
import com.enjoyun.bmc.core.service.CoreService;
import com.cc.self.model.raw.SelfBus;
import com.cc.self.service.SelfBusService;


@Controller(value = "com.cc.self.ctrl.SelfBusCtrllor")
@RequestMapping("selfbus")
public class SelfBusCtrllor {
	@Autowired
	private CoreService aCoreService;
	@Autowired
	private SelfBusService aSelfBusService;
	
	/**
	 * 根据组织查询列表
	 * @param ono 组织代码
	 * @return SelfBus[]
	 */
	@RequestMapping(value = "list", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getSelfBusList(
			@RequestParam(value = "code", required=false) String code,
			@RequestParam(value = "wx_no", required=false) String wx_no,
			@RequestParam(value = "gs_no", required=false) String gs_no,
			@RequestParam(value = "customer", required=false) String customer,
			@RequestParam(value = "bdt", required=false) String bdt,
			@RequestParam(value = "edt", required=false) String edt,
			@RequestParam(value = "bg_no", required=false) String bg_no,
			@RequestParam(value = "status", required=false) Integer status,
			@RequestParam(value = "ywy", required=false) String ywy,
			@RequestParam(value = "start", required=false) Integer start,
			@RequestParam(value = "limit", required=false) Integer limit
	 ) {
		try{
			int total = aSelfBusService.getSelfBusCount(code, wx_no, gs_no, customer, bdt, edt, bg_no, status, ywy);
			return WebUtil.getSuccessMap(aSelfBusService.getSelfBusList(code, wx_no, gs_no, customer, bdt, edt, bg_no, status, ywy, start, limit));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}
	
	/**
	 * 获取实体
	 * @param id 主键
	 * @return SelfBus
	 */
	@RequestMapping(value = "get", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getSelfBus(@RequestParam(value = "id") int key) {
		try{
			aCoreService.assertFunctionAuth("selfbus/start");
			return WebUtil.getSuccessMap(aSelfBusService.getSelfBus(key));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}

	/**
	 * 创建实体
	 * @param data 实体JSON
	 * @return SelfBus
	 */
	@RequestMapping(value = "create", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> createSelfBus(@RequestParam(value = "data") String data) {
		try{
			aCoreService.assertFunctionAuth("selfbus/create");
			SelfBus entity = AppUtil.toObject(data, SelfBus.class);
			return WebUtil.getSuccessMap(aSelfBusService.createSelfBus(entity));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}

	/**
	 * 更新实体
	 * @param data 实体JSON
	 * @return SelfBus
	 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateSelfBus(@RequestParam(value = "data") String data) {
		try{
			aCoreService.assertFunctionAuth("selfbus/update");
			SelfBus entity = AppUtil.toObject(data, SelfBus.class);
			return WebUtil.getSuccessMap(aSelfBusService.updateSelfBus(entity));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}

	/**
	 * 删除实体
	 * @param id 主键
	 * @return id
	 */
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> deleteSelfBus(@RequestParam(value = "id") int key) {
		try{
			aCoreService.assertFunctionAuth("selfbus/delete");
			return WebUtil.getSuccessMap(aSelfBusService.deleteSelfBus(key));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}
	
	/**
	 * 删除实体
	 * @param id 主键
	 * @return id
	 */
	@RequestMapping(value = "status", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> deleteSelfBus(@RequestParam(value = "id") int id,
			@RequestParam(value = "status") int status
	) {
		try{
			aCoreService.assertFunctionAuth("selfbus/delete");
			return WebUtil.getSuccessMap(aSelfBusService.updateSelfBusStatus(id, status));
		}catch (Exception e){
			return WebUtil.getFailureMap(e.getMessage());
		}
	}
	
}

